<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

class MenusController extends AppController {

    var $name = 'Menus';

    function admin_index() {
        $this->layout = 'ajax';
        $this->Menu->recursive = -1;
        //$menus = $this->Menu->find("all");
        $menus = $this->Menu->find("all", array("fields" => array("Menu.id", "Menu.nombre", "Menu.url", "Menu.icono")));
        $this->set('menus', $menus);
    }

    function admin_add() {
        $this->layout = 'ajax';
        $this->set('tabs', $this->Menu->Tab->find('list', array('order' => 'titulo ASC', 'fields' => array('Tab.id', 'Tab.titulo', 'Tab.order'))));

        if (!empty($this->data)) {
            if ($this->Menu->save($this->data)) {
                $this->Session->setFlash("Menú Creado con exito");
                $this->redirect(array('controller' => 'Menus', 'action' => 'index'));
            };
        }
    }

    function ver($id) {
        $this->set('cod', $this->Session->read('cod'));
        $this->Menu->recursive = -1;
        $lista = $this->Menu->find('all', array('conditions' => array('tab_id' => $id), 'fields' => array('Menu.id', 'Menu.nombre'), 'order' => array('Menu.order ASC')));
        $this->set('listado', $lista);
    }

    function admin_ver($id) {
        $this->set('cod', $this->Session->read('cod'));
        $lista = $this->Menu->find('all', array('conditions' => array('tab_id' => $id), 'fields' => array('Menu.id', 'Menu.nombre'), 'order' => array('Menu.order ASC')));
        $this->set('listado', $lista);
    }

    function admin_edit($id = null) {
        if (empty($this->data)) {
            $this->data = $this->Menu->find("first", array("conditions" => array("Menu.id" => $id)));
            $this->set('tabs', $this->Menu->Tab->find('list', array('order' => 'titulo ASC', 'fields' => array('Tab.id', 'Tab.titulo', 'Tab.order'))));
        } else {
            if ($this->Menu->save($this->data)) {
                $this->Session->setFlash('Menu Editado con éxito');
                $this->redirect(array('controller' => 'Menus', 'action' => 'index'));
            }
        }
    }

    function admin_delete($id) {
        if ($this->Menu->delete($id)) {
            $this->Session->setFlash('Menú Borrado con exito');
            $this->redirect(array('controller' => 'Menus', 'action' => 'index'));
        }
    }

}

?>